package com.zou.lotterylucky.data

import io.objectbox.annotation.Backlink
import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id
import io.objectbox.relation.ToMany

// 订单
@Entity
class DealEntity {
    @Id
    var sqlId: Long = 0L

    @Backlink(to = "deal")
    lateinit var bets: ToMany<BetEntity> //关联到每注
    var createTime: Long = 0L //生成订单的时间
    var isNetTime: Boolean = false //是否是网络时间
    var betEndTime = 0L //本场结束的时间
    var indexOfDay: Int = 0 //订单序号，每日从1开始计算
    var synced = false // 同步状态
    var syncing = false // 正在同步
    var syncError = false // 同步错误
    var needDelete = false // 需要删除

    /**
     * 订单归属 0K 1F 2D 3ST
     */
    var belongTo: String = ""

    fun getTotal(): Double {
        return bets.sumByDouble {
            it.betMoney.toDouble()
        }
    }

    override fun toString(): String {
        return "DealEntity(sqlId=$sqlId, bets=$bets, createTime=$createTime, isNetTime=$isNetTime, betEndTime=$betEndTime, indexOfDay=$indexOfDay, synced=$synced, syncing=$syncing, syncError=$syncError, needDelete=$needDelete, belongTo=$belongTo)"
    }
}